import 'package:flutter/material.dart';

class MainPage extends StatefulWidget {
  MainPage({this.pages});
  List<Widget> pages;

  @override
  _MainState createState() => _MainState();
}

class _MainState extends State<MainPage> {
  int _selectIndex = 0;
  final _tabbarNames = ['首页', '测试', '动画', '我的'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
        title: Text(_tabbarNames[_selectIndex]),
      ),
      body: Center(
        child: widget.pages[_selectIndex],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.textsms), label: '测试'),
          BottomNavigationBarItem(icon: Icon(Icons.games), label: '动画'),
          BottomNavigationBarItem(icon: Icon(Icons.adb), label: '我的')
        ],
        currentIndex: _selectIndex,
        selectedItemColor: Colors.amber[800],
        unselectedItemColor: Colors.blue,
        onTap: _selectTabbarIndex,
        type: BottomNavigationBarType.fixed,
      ),
    );
  }

  void _selectTabbarIndex(int index) {
    setState(() {
      _selectIndex = index;
    });
  }
}
